package com.reading.service.impl;

import com.reading.feign.UserFeignClient;
import com.reading.mapper.ShellMapper;
import com.reading.mapper.ShellRecordMapper;
import com.reading.pojo.GlodVO;
import com.reading.pojo.ShellRecord;
import com.reading.pojo.user.User;
import com.reading.service.ShellRecordService;
import com.reading.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ShellRecordServiceImpl implements ShellRecordService {

    @Autowired
    private ShellRecordMapper shellRecordMapper;

    @Autowired
    private UserFeignClient userFeignClient;

    @Override
    public R save(ShellRecord shellRecord) {
        shellRecordMapper.save(shellRecord);
        return R.ok().message("签到完成");
    }

    @Override
    public List<ShellRecord> findAll(Integer userId) {
        return shellRecordMapper.findAll(userId);
    }

    @Override
    public void saveReceiveEmail(Integer id) {
        ShellRecord shellRecord = new ShellRecord();
        shellRecord.setRecord("绑定邮箱");
        shellRecord.setNumber(30000);
        shellRecord.setUserId(id);
        shellRecord.setCreateTime(new Date());
        shellRecordMapper.save(shellRecord);

        User user = userFeignClient.findOne(id);
        GlodVO glodVO = new GlodVO();
        glodVO.setId(user.getId());
        glodVO.setGlod2(user.getUserglod2()+30000);
        userFeignClient.updateUserGlod2(glodVO);
    }

    @Override
    public ShellRecord findOneEmail(Integer id) {
        return shellRecordMapper.findOneEmail(id);
    }

    @Override
    public void saveReceivePhone(Integer id) {
        ShellRecord shellRecord = new ShellRecord();
        shellRecord.setRecord("绑定手机号");
        shellRecord.setNumber(35000);
        shellRecord.setUserId(id);
        shellRecord.setCreateTime(new Date());
        shellRecordMapper.save(shellRecord);

        User user = userFeignClient.findOne(id);
        GlodVO glodVO = new GlodVO();
        glodVO.setId(user.getId());
        glodVO.setGlod2(user.getUserglod2()+35000);
        userFeignClient.updateUserGlod2(glodVO);
    }

    @Override
    public ShellRecord findOnePhone(Integer id) {
        return shellRecordMapper.findOnePhone(id);
    }

}
